UiHelper.button = UiHelper.frame:extend()
--- 创建button
---@param frameId number
---@param relation number-相对节点ID(def:hdzui.origin.game())
---@param align number-integer-参考blizzard:^FRAME_ALIGN FRAME_ALIGN_CENTER
---@param alignRelation number以-align-> alignParent 对齐 FRAME_ALIGN_CENTER
---@param x number-锚点X
---@param y number-锚点Y
---@param fdfName string-frame名称
---@param parent number-父节点ID(def:hdzui.origin.game())
---@param tag string-自定义tag名称(def:cache.tagIdx)
---@param id number-integer(def:0)
---@param w number-宽
---@param h number-高
---@param show bool-显示 隐藏
---@param click func-点击
---@param enter func-悬浮
---@param leave func-离开
---@param doubleClick func-双击
---@param img string-("UI\\Widgets\\ToolTips\\Human\\human-tooltip-background.blp")
---@param text string-文本
---textAlign 文本位置 z 居中  b 脚部
---TEXT_ALIGN_CENTER = 2 -- 文本对齐中 TEXT_ALIGN_LEFT = 10 -- 文本对齐左 TEXT_ALIGN_RIGHT = 34 -- 文本对齐右
---style-{fdfName="fdfName",family="fonts.ttf",size=8 * 0.001,flag=0,align=TEXT_ALIGN_CENTER}
function UiHelper.button:new(args)
    args = args or {}
    args.fdfType = "BUTTON"

    self.frame = UiHelper.frame(args)
    self.frameId = self.frame.frameId
    self.click = args.click
    self.enter = args.enter
    self.leave = args.leave
    self.doubleClick = args.doubleClick

    self.relation = args.relation or hdzui.origin.game()
    self.align = args.align or FRAME_ALIGN_CENTER
    self.alignRelation = args.alignRelation or FRAME_ALIGN_CENTER
    self.x = args.x
    self.y = args.y
    self.h = args.h or 0
    self.w = args.w or 0
    self.img = args.img
    self.text = args.text
    self.style = args.style
    self.show = args.show
    self.btTextAlign = args.btTextAlign
    if (self.click ~= nil and type(self.click) == "function") then
        self.frame:CLICK(self.click)
    end
    if (self.enter ~= nil and type(self.enter) == "function") then
        self.frame.ENTER(self.enter)
    end
    if (self.leave ~= nil and type(self.leave) == "function") then
        self.frame:LEAVE(self.leave)
    end
    if (self.doubleClick ~= nil and type(self.doubleClick) == "function") then
        self.frame:DOUBLE_CLICK(self.doubleClick)
    end

    self.args = deep_copy(args)
    self:BGsetTexture(self.img)
    self:LBsetText(self.text)

    return self
end

---清空frame所有锚点
function UiHelper.button:dfClearAllPoints()
    self.frame:dfClearAllPoints()
    return self
end

---backdrop图片路径
---@param args.img string 图片路径
---@param img string 图片路径
function UiHelper.button:BGsetTexture(img)
    self.img = img or "UI\\Widgets\\ToolTips\\Human\\human-tooltip-background.blp"
   
    if self.BG == nil then
        self.BG =
            UiHelper.backdrop({parent = self.frameId}):dfClearAllPoints():dfpoint(0,0,FRAME_ALIGN_LEFT_TOP,self.frameId,FRAME_ALIGN_LEFT_TOP):dfpoint(0, 0, FRAME_ALIGN_RIGHT_BOTTOM, self.frameId, FRAME_ALIGN_RIGHT_BOTTOM):dfbackdrop(self.img)
    else
        self.BG:dfbackdrop(img)
    end
    return self
end

---按钮文本
function UiHelper.button:LBsetText(text)
    self.text = text or "测试"
   
    if self.text ~= nil then
        if self.LB == nil then
            self.LB = UiHelper.label({parent = self.BG.frameId}):dfClearAllPoints():dfpoint(0,0,FRAME_ALIGN_LEFT_TOP,self.frameId,FRAME_ALIGN_LEFT_BOTTOM):dfpoint(0,0,FRAME_ALIGN_RIGHT_TOP,self.frameId,FRAME_ALIGN_RIGHT_BOTTOM):dfsetTextAlignment(TEXT_ALIGN_CENTER)
        end
    end
    if self.LB ~= nil then
        self.frame:dftextid(self.LB.frameId, text)
    end
    return self
end

---设置宽高
function UiHelper.button:dfsize(w, h)
    self.w = w
    self.h = h
    self.frame:dfsize(w, h)
    return self
end

---设置锚点 相对位置{point,relativeFrame,relativePoint}
function UiHelper.button:dfpoint(x, y, point, relativeFrame, relativePoint)
    self.frame:dfpoint(x, y, point, relativeFrame, relativePoint)
    return self
end
---偏移
---@param relation number-相对节点ID(def:hdzui.origin.game())
---@param x number-锚点X
---@param y number-锚点Y
function UiHelper.button:dfpointp(x, y, relation, align, alignRelation)
    self.frame:dfpointp(x, y, relation, align, alignRelation)
    return self
end

---设置绝对位置
function UiHelper.button:dfAbsolutePoint(x, y, point)
    self.frame:dfAbsolutePoint(x, y, point)
    return self
end

---显示
function UiHelper.button:dfshow(show)
    if show==nil then
        show=true
    end
    self.frame:show(show)
    
    return self
end
---隐藏
function UiHelper.button:dfhide()
  
    self.frame:hide()
    return self
end


---点击事件
function UiHelper.button:CLICK(align)
    self.frame:CLICK(align)
    return self
end
---悬浮事件
function UiHelper.button:ENTER(align)
    self.frame:ENTER(align)
    return self
end
---离开事件
function UiHelper.button:LEAVE(align)
    self.frame:LEAVE(align)
    return self
end
---释放事件
function UiHelper.button:RELEASE(align)
    self.frame:RELEASE(align)
    return self
end
--双击事件
function UiHelper.button:DOUBLE_CLICK(align)
    self.frame:DOUBLE_CLICK(align)
    return self
end